package com.rylan.controller;

import com.rylan.entity.Room;
import com.rylan.entity.Type;
import com.rylan.repository.RoomRepository;
import com.rylan.repository.TypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author rylan
 * @description
 */
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomRepository roomRepository;
    @Autowired
    private TypeRepository typeRepository;
    @GetMapping("/findAll/{index}/{limit}")
    public List<Room> findAll(@PathVariable("index") int index,@PathVariable("limit") int limit){
        return roomRepository.findAll(index,limit);
    }
    @DeleteMapping("/deleteById/{id}")
    public void DeleteById(@PathVariable("id") long id){
        roomRepository.deleteById(id);
    }
    @GetMapping("/findTypes")
    public List<Type> findTypes(){
        return typeRepository.findAll();
    }
    @PostMapping("/save")
    public void save(@RequestBody Room room){
        roomRepository.save(room);
    }
    @GetMapping("/findById/{id}")
    public Room findById(@PathVariable("id") long id){
        return roomRepository.findById(id);
    }
    @PutMapping("/update")
    public void update(@RequestBody Room room){
        roomRepository.update(room);
    }

}
